package cn.cmm;

import java.util.Scanner;

/**
 * Created by Lenovo on 2019/1/6.
 */
public class Game {
    //创建玩家和电脑的对象
    Person person=new Person();
    Computer computer=new Computer();
    int count=0;//对战次数
    Scanner input = new Scanner(System.in);
    int choose;
    int personScore=0;//玩家的得分
    int computerScore=0;//电脑的得分

    //主菜单类
    public void menu() {
        System.out.println("--------------欢迎进入游戏世界---------------------");
        System.out.println("\t\t*******************\t\t");
        System.out.println("\t\t***\t猜拳,开始\t***\t\t");
        System.out.println("\t\t*******************\t\t");
        System.out.println("出拳规则:1.剪刀2.石头3.布");
        System.out.println("请选择对方角色(1:刘备2:孙权3:曹操)");
    }

    public void start() {
        do {
            choose = input.nextInt();
            switch (choose) {
                case 1:
                    computer.setName("刘备");
                    break;
                case 2:
                    computer.setName("孙权");
                    break;
                case 3:
                    computer.setName("曹操");
                    break;
                default:
                    System.out.println("输入错误，请重新输入!");
                    continue;
            }
            break;
        } while (true);
        System.out.println("你选择了" +computer.getName() + "对战！");
        System.out.print("请输入您的名字：");
        person.setNames(input.next()) ;
        System.out.println(person.getNames() + "\tVS\t" + computer.getName());
    }

    public void startGame() {
        System.out.println("\n要开始码?(y/n)");
        String con = input.next();

        while (con.equals("y")) {
            int perFist;
            int compFist;
            perFist = person.showInfo();
            compFist = computer.showInfo();
            if ((perFist == 1 && compFist == 1)
                    || (perFist == 2 && compFist == 2)
                    || (perFist == 3 && compFist == 3)) {
                System.out.println("结果:和局,你没有得分，真衰!\n");

            } else if ((perFist == 1 && compFist == 3)
                    || (perFist == 2 && compFist == 1)
                    || (perFist == 3 && compFist == 2)) {
                personScore++;
                System.out.println("结果:恭喜,你赢了，得分了!");
            } else {
                computerScore++;
                System.out.println("结果说:^_^,你输了,真笨!\n");
            }
            count++;
            System.out.print("是否开始下一轮(y/n)?");
            String fon=input.next();
            if (fon.equals("n")){
                break;
            }
        }
    }
    //比赛结果
    public void showResult(){
        System.out.println("_______________________________");
        System.out.println(person.getNames()+"VS"+computer.getName());
        System.out.println("对战次数"+count+"次");
        System.out.println("_______________________________");
    }
    //比赛得分
    public void score(){
        System.out.println("姓名\t得分");
        System.out.println(person.getNames()+"\t"+personScore);
        System.out.println(computer.getName()+"\t"+computerScore);
        if (personScore>computerScore){
            System.out.println("厉害哟，连电脑都不是你的对手！");
        }
        else if(personScore==computerScore){
            System.out.println("还差一点儿就能战胜电脑了！");
        }else{
            System.out.println("继续加油！");
        }
    }
}
